package cn.itsource.org.service.impl;

import cn.itsource.basic.util.PageList;
import cn.itsource.org.domain.Department;
import cn.itsource.org.mapper.DepartmentMapper;
import cn.itsource.org.query.DepartmentQuery;
import cn.itsource.org.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper mapper;

    @Override
    public void add(Department department) {
        mapper.add(department);
    }

    @Override
    public void update(Department department) {
        mapper.update(department);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public Department fendById(Long id) {
        return mapper.fendById(id);
    }

    @Override
    public List<Department> findAll() {
        return mapper.findAll();
    }

    @Override
    public PageList<Department> queryByPage(DepartmentQuery query) {
        Integer count = mapper.queryByCount(query);
        if (count == 0 || count==null){
            return new PageList<>(0,new ArrayList<>());
        }
        List<Department> departments=mapper.queryByPage(query);
        return new PageList<>(count,departments);
    }

}

